﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PMSGSC.DAL;
using PMSGSC.BLL;
using DevExpress.XtraEditors;

namespace PMSGSC.App
{
    public partial class ucLoadVendor : UserControl
    {
        public ucLoadVendor()
        {
            InitializeComponent();
        }
        public bool isChanges;
        public void SetValue(string code, string name, string id)
        {
            txtCode.Text = code;
            txtName.Text = name;
            lbid.Text = id;
        }
          
        private void txtCode_Validating(object sender, CancelEventArgs e)
        {
            if (txtCode.Text != "")
            {
                Vendor vendor = Vendor_BLL.GetDataByCode(txtCode.Text, frmMain.ship.Ship_ID);
                if (null == vendor)
                {
                    XtraMessageBox.Show("Vendor not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.Cancel = true;
                }
                else
                {
                    txtCode.Text = vendor.CodeVendor;
                    txtName.Text = vendor.NameVendor;
                    lbid.Text = vendor.Vendor_ID.ToString();
                }
            }
            else
            {
                txtCode.Text = "";
                txtName.Text = "";
                lbid.Text = "";
            }
        }

        private void txtName_Validating(object sender, CancelEventArgs e)
        {

            if (txtName.Text != "")
            {
                Vendor vendor = Vendor_BLL.GetDataByName(txtName.Text, frmMain.ship.Ship_ID);
                if (null == vendor)
                {
                    XtraMessageBox.Show("Vendor not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.Cancel = true;
                }
                else
                {
                    txtCode.Text = vendor.CodeVendor;
                    txtName.Text = vendor.NameVendor;
                    lbid.Text = vendor.Vendor_ID.ToString();
                }
            }
            else
            {
                txtCode.Text = "";
                txtName.Text = "";
                lbid.Text = "";
            }
        }

        private void txtName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmGirdVendor frmVendor = new frmGirdVendor();
            frmVendor.ShowDialog();
            if (null != frmVendor.vendor)
            {
                txtCode.Text = frmVendor.vendor.CodeVendor;
                txtName.Text = frmVendor.vendor.NameVendor;
                lbid.Text = frmVendor.vendor.Vendor_ID.ToString();
                isChanges = true;
            }
        }
    }
}
